﻿using System;
using System.Collections.Generic;
using LinFu.Reflection;

namespace CoreEx.Wcf.Common.Implementation
{
    /// <summary>
    /// Provides a implementation of the <see cref="IActionLoader{TTarget,TInput}"/> interface that 
    /// enables an <see cref="Action{T}"/> to be supplied for each loaded type.
    /// </summary>
    /// <remarks>
    /// In order to prevent reinventing the wheel, this implementation is used together with the <see cref="Loader{TTarget}"/> class 
    /// to load the list of known types.
    /// </remarks>
    public class TypeActionLoader : IActionLoader<IList<Type>, Type>
    {
        public IEnumerable<Action<IList<Type>>> Load(Type input)
        {
            var actionList = new List<Action<IList<Type>>>();
            //Create an action delegate that adds the type to the list of known types.
            actionList.Add(repository => repository.Add(input));
            return actionList;
        }

        public bool CanLoad(Type inputType)
        {
            return true;
        }
    }
}